﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QuanLyBanHang_NewApp.DBAccess;

namespace QuanLyBanHang_NewApp.DAL
{
    public class PhieuNhapDAL
    {
        private dbConnection conn;

        public PhieuNhapDAL()
        {
            conn = new dbConnection();
        }

        //public bool insertPN(long manv, long mancc, string ngaylap, double tonggia)
        //{
        //    string query = "insert into PHIEUNHAP values(@manv, @mancc, @ngaylap, @tonggia)";
        //    SqlParameter[] p = new SqlParameter[4];
        //    p[0] = new SqlParameter("@manv", manv);
        //    p[1] = new SqlParameter("@mancc", mancc);
        //    p[2] = new SqlParameter("@ngaylap", ngaylap);
        //    p[3] = new SqlParameter("@tonggia", tonggia);
            
        //    return conn.execInsertQuery(query, p);
        //}

        public bool insertPN(out long mapn, long manv, long mancc, double tonggia)
        {
            string query = "insertPN";
            SqlParameter[] p = new SqlParameter[5];
            p[0] = new SqlParameter("@manv", manv);
            p[1] = new SqlParameter("@mancc", mancc);
            p[2] = new SqlParameter("@ngaylap", DateTime.Now.Date);
            p[3] = new SqlParameter("@tong", tonggia);
            p[4] = new SqlParameter("@mapn", SqlDbType.BigInt);
            p[4].Direction = ParameterDirection.Output;
            bool kq = conn.execInsertProcedureQuery(query, p);
            mapn = int.Parse(p[4].Value.ToString());
            return kq;
        }

        public bool insertCTPN(long mapn, long masp, long soluong, double dongia)
        {
            string query = "insert into CHITIETPHIEUNHAP values(@mapn, @masp, @soluong, @dongia)";
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@mapn", mapn);
            p[1] = new SqlParameter("@masp", masp);
            p[2] = new SqlParameter("@soluong", soluong);
            p[3] = new SqlParameter("@dongia", dongia);

            return conn.execInsertQuery(query, p);
        }

    }
}
